from celery import shared_task
from django.utils import timezone
import datetime
from book.models import BookRecordModel

@shared_task
def check_to_books():
    now = timezone.now()
    due_soon = BookRecordModel.objects.filter(
        return_date__lt=now + datetime.timedelta(days=7),
        return_date__gt=now
    )
    for record in due_soon:
         print(f"Reminder to {record.reader}: Your book '{record.book.title}' is due in {int((record.return_date - now).days)} days.")
    print('ok')